//------------------Sonic CD Flower Script--------------------//
//--------Scripted by Christian Whitehead 'The Taxman'--------//
//-------Unpacked By Rubberduckycooly's Script Unpacker-------//

// Aliases
#alias Object.Value0	:	Object.Timer

// States
#alias 0	:	FLOWER_SEED_SPAWN
#alias 1	:	FLOWER_SEED_FALL

#alias 2	:	FLOWER_SEED_PLANTED_1
#alias 3	:	FLOWER_SEED_PLANTED_2
#alias 4	:	FLOWER_SEED_PLANTED_3

#alias 5	:	FLOWER_ROOT_GROWTH_1
#alias 6	:	FLOWER_ROOT_GROWTH_2

#alias 7	:	FLOWER_ANIM_1
#alias 8	:	FLOWER_ANIM_2
#alias 9	:	FLOWER_ANIM_3

// Collision Sides
#alias 0	:	CSIDE_FLOOR


sub ObjectMain
	switch Object.State
	case FLOWER_SEED_SPAWN
		Object.Frame = 8
		Object.Timer++
		if Object.Timer == 20
			Object.Timer = 0
			Object.State++
		end if
		break

	case FLOWER_SEED_FALL
		Object.Frame   = Object.Timer
		Object.Frame >>= 2

		Object.Timer++
		Object.Timer &= 7

		Object.YPos += 0x20000
		ObjectTileCollision(CSIDE_FLOOR, 0, 8, 0)
		if CheckResult == true
			Object.YPos += 0x80000
			Object.State++
			Object.Timer = 0
			Object.Frame = 2
		end if
		break

	case FLOWER_SEED_PLANTED_1
		Object.Timer++
		if Object.Timer == 4
			Object.Timer = 0
			Object.State++
			Object.Frame = 3
		end if
		break
		
	case FLOWER_SEED_PLANTED_2
		Object.Timer++
		if Object.Timer == 4
			Object.Timer = 0
			Object.State++
			Object.Frame = 2
		end if
		break

	case FLOWER_SEED_PLANTED_3
		Object.Timer++
		if Object.Timer == 4
			Object.Timer = 0
			Object.State++
			Object.Frame = 3
		end if
		break

	case FLOWER_ROOT_GROWTH_1
		Object.Timer++
		if Object.Timer == 5
			Object.Timer = 0
			Object.State++
			Object.Frame = 4
		end if
		break

	case FLOWER_ROOT_GROWTH_2
		Object.Timer++
		if Object.Timer == 4
			Object.Timer = 0
			Object.State++
			Object.Frame = 5
		end if
		break

	case FLOWER_ANIM_1
		Object.Timer++
		if Object.Timer == 2
			Object.Timer = 0
			Object.State++
			Object.Frame = 6
		end if
		break

	case FLOWER_ANIM_2
		Object.Timer++
		if Object.Timer == 20
			Object.Timer = 0
			Object.State++
			Object.Frame = 7
		end if
		break

	case FLOWER_ANIM_3
		Object.Timer++
		if Object.Timer == 20
			Object.Timer = 0
			Object.State--
			Object.Frame = 6
		end if
		break

	end switch
end sub


sub ObjectDraw
	DrawSprite(Object.Frame)
end sub


sub ObjectStartup
	LoadSpriteSheet("R4.5/Boss.gif")

	SpriteFrame(-4, -8, 8, 16, 52, 1)		// #0 - Seed Frame 0
	SpriteFrame(-4, -8, 8, 16, 52, 16)		// #1 - Seed Frame 1

	SpriteFrame(-8, -16, 16, 16, 18, 1)		// #2 - Planted Seed Frame 0
	SpriteFrame(-8, -16, 16, 16, 35, 1)		// #3 - Planted Seed Frame 1

	SpriteFrame(-8, -16, 16, 16, 1, 1) 		// #4 - Flower Growth Frame 0
	SpriteFrame(-12, -24, 24, 24, 1, 42) 	// #5 - Flower Growth Frame 1

	SpriteFrame(-12, -48, 24, 48, 1, 18) 	// #6 - Flower Frame 0
	SpriteFrame(-12, -48, 24, 48, 26, 18)	// #7 - Flower Frame 1

	SpriteFrame(0, 0, 0, 0, 0, 0)			// #8 - Cheat Sprite
end sub


// ========================
// Editor Subs
// ========================

sub RSDKDraw
	DrawSprite(0)
end sub


sub RSDKLoad
	LoadSpriteSheet("R4.5/Boss.gif")
	SpriteFrame(-12, -48, 24, 48, 1, 18) 	// #0 - Flower Frame 0

	SetVariableAlias(ALIAS_VAR_PROPVAL, "unused")
end sub
